gh-142048: Fix lost allocations on thread cleanup#142233
Merged
kumaraditya303 merged 2 commits intopython:mainfrom Dec 10, 2025
Merged
gh-142048: Fix lost allocations on thread cleanup#142233kumaraditya303 merged 2 commits intopython:mainfrom
kumaraditya303 merged 2 commits intopython:mainfrom
Conversation
kevmo314
commented
Dec 3, 2025
| // Flush the thread's local GC allocation count to the global count | ||
| // before the thread state is cleared, otherwise the count is lost. | ||
| _PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)tstate; | ||
| _Py_atomic_add_int(&tstate->interp->gc.young.count, |
Contributor
Author
There was a problem hiding this comment.
Since this is less common perhaps it's ok to allow the global GC count to go negative here? The compare-and-exchange loop is more accurate though, I can update to use that if preferred.
Contributor
There was a problem hiding this comment.
Yeah, I think going negative here is fine
colesbury
approved these changes
Dec 4, 2025
kumaraditya303
approved these changes
Dec 10, 2025
|
Thanks @kevmo314 for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Dec 10, 2025
…honGH-142233) (cherry picked from commit 49b1fb4) Co-authored-by: Kevin Wang <kevmo314@gmail.com>
|
Sorry, @kevmo314 and @kumaraditya303, I could not cleanly backport this to |
|
GH-142504 is a backport of this pull request to the 3.14 branch. |
|
GH-142506 is a backport of this pull request to the 3.13 branch. |
kumaraditya303
pushed a commit
to kumaraditya303/cpython
that referenced
this pull request
Dec 10, 2025
…up (pythonGH-142233) (cherry picked from commit 49b1fb4) Co-authored-by: Kevin Wang <kevmo314@gmail.com>
kumaraditya303
pushed a commit
that referenced
this pull request
Dec 10, 2025
kumaraditya303
pushed a commit
to kumaraditya303/cpython
that referenced
this pull request
Dec 10, 2025
…up (pythonGH-142233) (cherry picked from commit 49b1fb4) Co-authored-by: Kevin Wang <kevmo314@gmail.com>
kumaraditya303
added a commit
that referenced
this pull request
Dec 11, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes some lost allocation counts in the local allocation counters when threads are cleaned up.